﻿// ***********************************************************************
// Assembly         : Tx.OCC
// Author           : tianteng
// Created          : 09-10-2019
//
// Last Modified By : tianteng
// Last Modified On : 09-10-2019
// ***********************************************************************
// <copyright file="OccProjectorEx.cs" company="北京腾雪科技有限责任公司">
//     Copyright © 北京腾雪科技有限责任公司 2022
// </copyright>
// <summary></summary>
// ***********************************************************************
using Occt;

namespace Tx.OCC
{
    /// <summary>
    /// Class OccProjectorEx.
    /// </summary>
    public static class OccProjectorEx
    {
        /// <summary>
        /// Creates new algo.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="projector">The projector.</param>
        /// <returns>Algo.</returns>
        public static HLRBRep_Algo NewAlgo(TopoDS_Shape shape, HLRAlgo_Projector projector)
        {
            var algo = new HLRBRep_Algo();
            algo.Add(shape);
            algo.Projector = projector;
            algo.Update();
            algo.Hide();
            return algo;
        }

        /// <summary>
        /// Creates new polyalgo.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="projector">The projector.</param>
        /// <returns>PolyAlgo.</returns>
        public static HLRBRep_PolyAlgo NewPolyAlgo(TopoDS_Shape shape, HLRAlgo_Projector projector)
        {
            if (!BRepTools.Triangulation(shape, Precision.Infinite))
            {
                var incrementalMesh = new BRepMesh_IncrementalMesh(shape, 0.1);
            }
            var polyAlgo = new HLRBRep_PolyAlgo();
            polyAlgo.Load(shape);
            polyAlgo.Projector = projector;
            polyAlgo.Update();
            return polyAlgo;
        }

        /// <summary>
        /// News the HLR to shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="cs">The cs.</param>
        /// <returns>HLRToShape.</returns>
        public static HLRBRep_HLRToShape NewHLRToShape(TopoDS_Shape shape, gp_Ax2 cs)
        {
            return NewHLRToShape(shape, new HLRAlgo_Projector(cs));
        }

        /// <summary>
        /// News the HLR to shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="projector">The projector.</param>
        /// <returns>HLRToShape.</returns>
        public static HLRBRep_HLRToShape NewHLRToShape(TopoDS_Shape shape, HLRAlgo_Projector projector)
        {
            var algo = NewAlgo(shape, projector);
            return new HLRBRep_HLRToShape(algo);
        }


        /// <summary>
        /// News the poly HLR to shape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="cs">The cs.</param>
        /// <returns>PolyHLRToShape.</returns>
        public static HLRBRep_PolyHLRToShape NewPolyHLRToShape(TopoDS_Shape shape, gp_Ax2 cs)
        {
            return NewPolyHLRToShape(shape, new HLRAlgo_Projector(cs));
        }

        /// <summary>
        /// Creates new polyhlrtoshape.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="projector">The projector.</param>
        /// <returns>PolyHLRToShape.</returns>
        public static HLRBRep_PolyHLRToShape NewPolyHLRToShape(TopoDS_Shape shape, HLRAlgo_Projector projector)
        {
            var polyAlgo = NewPolyAlgo(shape, projector);
            var polyHlrToShape = new HLRBRep_PolyHLRToShape();
            polyHlrToShape.Update(polyAlgo);
            return polyHlrToShape;
        }
    }
}
